import kotlin.reflect.*
class Memomize<T,R>(val func:(T)->R) {
    var cache = mutableMapOf<T,R>()
    operator fun getValue(thisRef:Any?,property:KProperty<*>) = {n:T -> cache.getOrPut(n){func(n)}}
}

val fib: (Int) ->Long  by Memomize {
    n:Int->
        when(n){
            1,0 -> 1L
            else -> fib(n-1) + fib(n-2)
        }
}

println(fib(10))
println(fib(100))